#include <iostream>
#include <string>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int a[110][110];
int b[110][110];
int main()
{
    int n, m, r, s;
    cin >> n >> m;
    long long min = 99999999;
    int oi = -1;
    int oj = -1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
     cin >> r >> s;
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < s; j++)
        {
            cin >> b[i][j];
        }
    }
    for (int i = n - 1; i - r + 1 >= 0; i--)
    {
        for (int j = m - 1; j - s + 1 >= 0; j--)
        {
            long long tmp = 0;
            int tmpr = r - 1;
            for (int l = i; l >= i - r + 1; l--)
            {
                int tmps = s - 1;
                for (int h = j; h >= j - s + 1; h--)
                {
                    int d = a[l][h] - b[tmpr][tmps];
                    if(d<0){
                        d = -d;
                    }
                    tmp += d;
                    tmps--;
                }
                tmpr--;
            }
            if (tmp <= min)
            {
                min = tmp;
                oi = i;
                oj = j;
            }
        }
    }

    for (int i = oi - r + 1; i <= oi; i++)
    {
        for (int j = oj - s + 1; j <= oj; j++)
        {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}